
#ifndef variant_thread_h
#define variant_thread_h

#if Windows

#include <thread>

#else

#include <pthread.h>

namespace Riccsson{ namespace System{ namespace Threading {
	class Thread;
}}}

namespace std
{
	namespace chrono
	{
		int milliseconds( int millisec );
	}

	typedef void*(Riccsson::System::Threading::Thread::*Method)(void*);

	struct _data
	{
		Riccsson::System::Threading::Thread* _thread;
		Method _method;
		void* _arguments;
	};

	void* _thread_run(void* dataPtr);

	// Code example reference: http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
	class thread
	{
	private:
		pthread_t _internalThread;

		Method _Riccsson_method;

	public:
		
		//--------------------------------------------------------------------------------------
		thread( Method method, Riccsson::System::Threading::Thread* instance, void* arguments)
		{
			_data* data = new _data();
			data->_thread = instance;
			data->_method = method;
			data->_arguments = arguments;

			// Create thread.
			pthread_create(&_internalThread, /*null*/0, _thread_run, data);
			pthread_join( _internalThread, /*null*/0 );
		}

		//--------------------------------------------------------------------------------------
		void detach()
		{
			// Detach.
			pthread_detach(_internalThread);
		}
		
		//--------------------------------------------------------------------------------------
		bool joinable()
		{
			//int state_out(0);
			//int state = pthread_attr_getdetachstate(&_thread_attribute, &state_out);
			return false;
		}
		
		//--------------------------------------------------------------------------------------
		void join()
		{
			// TODO: What is the returnValue???????
			void** returnValue;
			pthread_join(_internalThread, returnValue);
		}
	};

	class this_thread
	{
	public:
		static void sleep_for(int milliseconds);
	};
}

#endif

#endif